package abel.wlmr.model.type;

import abel.wlmr.model.WlmrField;

public class MeterStatus2Field extends WlmrField {

    private byte clockLow;
    private byte battery1Low;
    private byte battery2Low;
    private byte battery3Low;
    private byte battery4Low;
    private byte battery5Low;

    public MeterStatus2Field() {
        super(2);
    }

    @Override
    public int getValue() {
        return clockLow | battery1Low << 1
            | battery2Low << 2 | battery3Low << 3
            | battery4Low << 4 | battery5Low << 5;
    }

    @Override
    public void parseValue(int v) {
        clockLow = (byte) (v & 1);
        battery1Low = (byte) (v & 2 >> 1);
        battery2Low = (byte) ((v & 4) >> 2);
        battery3Low = (byte) ((v & 8) >> 3);
        battery4Low = (byte) ((v & 0x10) >> 4);
        battery5Low = (byte) ((v & 0x20) >> 5);
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return String.format(
            "{clockLow:%s, battery1Low:%s, battery2Low:%s, battery3Low:%s, battery4Low:%s, battery5Low:%s}", clockLow,
            battery1Low, battery2Low, battery3Low, battery4Low, battery5Low);
    }

    /**
     * @return the clockLow
     */
    public byte getClockLow() {
        return clockLow;
    }

    /**
     * @param v
     *            the clockLow to set
     */
    public void setClockLow(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }
        this.clockLow = v;
    }

    /**
     * @return the battery1Low
     */
    public byte getBattery1Low() {
        return battery1Low;
    }

    /**
     * @param v
     *            the battery1Low to set
     */
    public void setBattery1Low(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }
        this.battery1Low = v;
    }

    /**
     * @return the battery2Low
     */
    public byte getBattery2Low() {
        return battery2Low;
    }

    /**
     * @param battery2Low
     *            the battery2Low to set
     */
    public void setBattery2Low(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }
        this.battery2Low = v;
    }

    /**
     * @return the battery3Low
     */
    public byte getBattery3Low() {
        return battery3Low;
    }

    /**
     * @param battery3Low
     *            the battery3Low to set
     */
    public void setBattery3Low(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }
        this.battery3Low = v;
    }

    /**
     * @return the battery4Low
     */
    public byte getBattery4Low() {
        return battery4Low;
    }

    /**
     * @param battery4Low
     *            the battery4Low to set
     */
    public void setBattery4Low(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }
        this.battery4Low = v;
    }

    /**
     * @return the battery5Low
     */
    public byte getBattery5Low() {
        return battery5Low;
    }

    /**
     * @param battery5Low
     *            the battery5Low to set
     */
    public void setBattery5Low(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }
        this.battery5Low = v;
    }

}
